
def cycle(n):
    hash = {}
    r = 1 # remainder
    i = 1 # counter
    while True:
        while r < n:
            r *= 10
            i += 1
        r = r % n
        if r == 0:
            return 0
        elif r in hash:
            return i - hash[r]
        else:
            hash[r] = i
        
print max([(cycle(i), i) for i in range(2, 1000)])[1] 

